package com.bkgy.modular.tpdidatacgl1870.controller;

import com.alibaba.fastjson.JSON;
import com.bkgy.modular.tpdidatacgl1870.entity.TPdiDataCgl1870;
import com.bkgy.modular.tpdidatacgl1870.entity.TPdiDataCgl1870ForQuery;
import com.bkgy.modular.tpdidatacgl1870.service.TPdiDataCgl1870Service;
import com.bkgy.sys.common.entity.IndocnoEntity;
import com.bkgy.sys.common.entity.InsertAndUpdateEntity;
import com.bkgy.sys.common.entity.JCommon;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.CodiUtil;
import io.github.yedaxia.apidocs.ApiDoc;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 镀锌1870PDI
 * @author 生成器生成
 * @date 2025-04-08 14:16:21
 */
@ApiDoc
@RestController
@RequestMapping("/tPdiDataCgl1870")
public class TPdiDataCgl1870Controller {

    @Resource
    private TPdiDataCgl1870Service tPdiDataCgl1870Service;

    /**
    * 添加记录
    * @param insertAndUpdateEntity 插入与更新专用实体类
    * @param loginToken            请求头（包含userId（用户id） & sname 用户姓名）
    */
    @CrossOrigin
    @PostMapping("/insert")
    @ResponseBody
    public ResultData<Object> insertDataTPdiDataCgl1870(@RequestBody InsertAndUpdateEntity<TPdiDataCgl1870> insertAndUpdateEntity
            , @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tPdiDataCgl1870Service.insertDataTPdiDataCgl1870(insertAndUpdateEntity.getEntity(), userId, CodiUtil.returnLm(sname));
    }

    /**
     * 根据主键删除对象
     * @param indocnoEntity 主键专用实体类
     * */
    @CrossOrigin
    @PostMapping("/deleteOne")
    @ResponseBody
    public ResultData<Object> deleteDataTPdiDataCgl1870One(@RequestBody IndocnoEntity indocnoEntity) {
        try {
            return tPdiDataCgl1870Service.deleteOne(indocnoEntity.getIndocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 根据主键字符串删除多个对象
     * @param indocnoEntity 主键专用实体类
     * */
    @CrossOrigin
    @PostMapping("/deleteMany")
    @ResponseBody
    public ResultData<Object> deleteDataTPdiDataCgl1870Many(@RequestBody IndocnoEntity indocnoEntity) {
        try {
            return tPdiDataCgl1870Service.deleteMany(indocnoEntity.getStr_indocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 修改记录
     * @param insertAndUpdateEntity 插入与更新专用实体类
     * @param loginToken 请求头（包含userId（用户id） & sname 用户姓名）
     */
    @CrossOrigin
    @PostMapping("/update")
    @ResponseBody
    public ResultData<Object> updateDataTPdiDataCgl1870(@RequestBody InsertAndUpdateEntity<TPdiDataCgl1870> insertAndUpdateEntity
            , @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tPdiDataCgl1870Service.updateDataTPdiDataCgl1870(insertAndUpdateEntity.getEntity(), userId, CodiUtil.returnLm(sname));
    }

    /**
     * 分页查看记录
     * @param tPdiDataCgl1870ForQuery 查询专用实体类
     */
    @CrossOrigin
    @PostMapping("/findByPage")
    @ResponseBody
    public ResultData<List<TPdiDataCgl1870>> findDataTPdiDataCgl1870ByPage(@RequestBody TPdiDataCgl1870ForQuery tPdiDataCgl1870ForQuery) {
        return tPdiDataCgl1870Service.findDataTPdiDataCgl1870ByPage(tPdiDataCgl1870ForQuery);
    }

    /**
     * 根据主键查询单条记录
     * @param indocnoEntity 主键专用实体类
     */
    @CrossOrigin
    @PostMapping("/findByIndocno")
    @ResponseBody
    public ResultData<TPdiDataCgl1870> findDataTPdiDataCgl1870ByIndocno(@RequestBody IndocnoEntity indocnoEntity) {
        return tPdiDataCgl1870Service.findDataTPdiDataCgl1870ByIndocno(indocnoEntity.getIndocno());
    }
}